package com.toefl.speaking.handler;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicNameValuePair;

import android.content.Context;

import com.toefl.speaking.util.AppConstans;
import com.toefl.speaking.util.AppUtils;

//��¼
public class LoginHandler {

	private static LoginHandler instance;

	private Login login;

	private LoginHandler() {

	}

	public static LoginHandler instance() {
		if (instance == null) {
			instance = new LoginHandler();
		}
		return instance;
	}

	public Login getLogin() {
		if (login == null) {
			login = new Login();
		}
		return login;
	}

	public String postLogin(Login login, Context context)
			throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		nameValuePairs.add(new BasicNameValuePair(AppConstans.Account, login
				.getAccount()));
		nameValuePairs.add(new BasicNameValuePair(AppConstans.Passwd, login
				.getPassword()));
		nameValuePairs.add(new BasicNameValuePair(AppConstans.KeepLogin, login
				.isKeepLogin() ? "yes" : "no"));
		nameValuePairs.add(new BasicNameValuePair(AppConstans.DeviceToken,
				login.getDeviceToken()));
		return AppUtils.doPost(AppConstans.INTERFACE_URL+"login", nameValuePairs);
	}

	public class Login {
		private String Account;
		private String Password;
		private boolean KeepLogin;
		private String DeviceToken;

		public String getAccount() {
			return Account;
		}

		public void setAccount(String account) {
			Account = account;
		}

		public String getPassword() {
			return Password;
		}

		public void setPassword(String password) {
			Password = password;
		}

		public boolean isKeepLogin() {
			return KeepLogin;
		}

		public void setKeepLogin(boolean keepLogin) {
			KeepLogin = keepLogin;
		}

		public String getDeviceToken() {
			return DeviceToken;
		}

		public void setDeviceToken(String deviceToken) {
			DeviceToken = deviceToken;
		}

	}

}
